package com.common.frame.listener

import android.view.animation.Animation

class AnimationListener(callback: ListenerBuilder.() -> Unit) : Animation.AnimationListener {

    val listener = ListenerBuilder().also(callback)

    override fun onAnimationStart(animation: Animation) {
        listener.onAnimationStart?.invoke(animation)
    }


    override fun onAnimationEnd(animation: Animation) {
        listener.onAnimationEnd?.invoke(animation)
    }

    override fun onAnimationRepeat(animation: Animation) {
        listener.onAnimationRepeat?.invoke(animation)
    }


    class ListenerBuilder {
        var onAnimationStart: ((Animation) -> Unit)? = null
        var onAnimationEnd: ((Animation) -> Unit)? = null
        var onAnimationRepeat: ((Animation) -> Unit)? = null

        fun onAnimationStart(action: (Animation) -> Unit) {
            onAnimationStart = action
        }

        fun onAnimationEnd(action: (Animation) -> Unit) {
            onAnimationEnd = action
        }

        fun onAnimationRepeat(action: (Animation) -> Unit) {
            onAnimationRepeat = action
        }
    }


}